#pragma once
#pragma once
#ifndef FILE_MANAGER_H
#define FILE_MANAGER_H
#include <vector>
#include "sql/Stat.h"
#include "Convertor.h"
#include "global.h"
#include <future>
#include "file.h"
using namespace std;
using namespace ment;

class Page;


class FileManager
{
public:
    //单例模式
    static FileManager* getInstance();
    static void release();
    ~FileManager();
private:
    static FileManager* instance;
    FileManager() {}
    FileManager(const FileManager&) {}
    FileManager& operator=(const FileManager&) = delete;
public:
    //更新
    void update(const char* id, Stat* newContent);


    bool isFileFull(string fileid);
    bool isAbleToInput(string fileid, string pageid, Stat* content);
    bool isAbleToInput(Page* page, Stat* content);

    //���䣺�����ļ���+ҳ��
    string allocPage(string fileid, PageType ft = PageType::table);
    string allocFile();

    //���ļ������
    Page* getPage(string fileid, string pageid);
    //future<Page*>  getPageAsync(string fileid, string pageid);
    file* getFile(string fileid);


    vector<string> multiplePut(vector<Stat*> records);
    vector<Stat*> multipleGet(vector<string> ids);
    void multipleUpdate(vector<string> ids, vector<Stat*> records);
    void multipleRemove(vector<string> ids);

    //��ȡ����ҳ���ļ�
    Page* getLastAvailablePage(string fileid);
    //future<Page*> getLastAvailablePageAsync(string fileid);
    file* getLastAvailableFile();
private:
    void releasePage(Page* page);
private:
    vector<file> files;
};

#endif // !FILE_MANAGER_H